package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ82 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle8201(cmd);
            case 0x02:
                return handle8202(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }


    private String handle8201(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:查询位置信息");
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8202(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:位置跟踪控制");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0x00,"按时间间隔、持续时间");
        list.put(0x11,"按距离间隔、持续距离");
        list.put(0x01,"按时间间隔、持续距离");
        list.put(0x10,"按距离间隔、持续时间");
        list.put(0xFF,"停止当前跟踪(终端忽略后面字段)");
        int type = cmd.readInt(4);
        builder.append("规则("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("时间(秒)/距离间隔（米）:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("持续时间（秒）/距离（米）:"+cmd.readInt(4));
        builder.append("\r\n");
        return builder.toString();
    }


}
